package com.itfreer.cms.dao.content;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.springframework.beans.BeanUtils;

import com.itfreer.cms.entity.content.CommentEntity;
import com.itfreer.cms.entity.content.DocumentEntity;
import com.itfreer.form.api.JdbcBaseEntity;

/**
 * 文章管理类
 */
@Entity(name = "cms_document")
public class JdbcDocumentEntity implements JdbcBaseEntity<DocumentEntity>, Serializable {

	private static final long serialVersionUID = -3113990430827435245L;

	/**
	 * id值，主键，唯一值
	 * 系统应用中必需关联此值
	 */
	@Id
	@Column(name = "id", length = 50, nullable = false)
	private String id;
	
	/**
	 * 站点名称
	 */
	@Column(name = "s_siteid", length = 50, nullable = true)
	private String siteId;
	
	/**
	 * 原始ID，用于记录从不同站点之间提交文章
	 */
	@Column(name = "s_originalid", length = 50, nullable = true)
	private String originalid;
	
	/**
	 * 所属专题
	 */
	@Column(name = "s_subject", length = 20, nullable = true)
	private String subject;
	
	/**
	 * 所属栏目
	 */
	@Column(name = "s_column", length = 50, nullable = true)
	private String column;
	
	/**
	 * 标题
	 */
	@Column(name = "s_title", length = 100, nullable = false)
	private String title;
	
	/**
	 * 完整标题
	 */
	@Column(name = "s_fullTitle", length = 500, nullable = true)
	private String fullTitle;
	
	/**
	 * 标题图
	 */
	@Column(name = "s_titlePicture", length = 1000, nullable = true)
	private String titlePicture;

	/**
	 * 关键词
	 */
	@Column(name = "s_main", length = 50, nullable = true)
	private String main;
	
	/**
	 * 发布人
	 */
	@Column(name = "s_release", length = 20, nullable = true)
	private String release;
	
	/**
	 * 发布时间
	 */
	@Column(name = "d_publishdate", nullable = true)
	private Date publishDate;

	/**
	 * 作者
	 */
	@Column(name = "s_author", length = 10, nullable = true)
	private String author;
	
	/**
	 * 来源
	 */
	@Column(name = "s_source", length = 20, nullable = true)
	private String source;

	/**
	 * 描述
	 */
	@Column(name = "s_describe", length = 1000, nullable = true)
	private String describe;
	
	/**
	 * 状态
	 */
	@Column(name = "s_state", length = 20, nullable = true)
	private String state;

	// ---- 新闻内容    -----
	/**
	 * 新闻正文
	 */
	@Column(name = "c_text", length = 4000, nullable = true)
	private String text;
	// ---- 新闻内容 end -----
	
	// ---- 图集内容    -----
	/**
	 * 图集
	 */
	@Column(name = "s_images", length = 4000, nullable = true)
	private String images;
	// ---- 图集内容 end -----
	
	// ---- 下载内容    -----
	/**
	 * 下载文件
	 */
	@Column(name = "s_file", length = 200, nullable = true)
	private String file;
	
	/**
	 * 文件大小
	 */
	@Column(name = "l_size", length = 20, nullable = true)
	private Long size;

	/**
	 * 授权方式
	 */
	@Column(name = "s_license", length = 20, nullable = true)
	private String license;

	/**
	 * 界面语言
	 */
	@Column(name = "s_language", length = 20, nullable = true)
	private String language;

	/**
	 * 推荐星级
	 */
	@Column(name = "i_star", length = 20, nullable = true)
	private Integer star;

	/**
	 * 运行环境
	 */
	@Column(name = "s_system", length = 50, nullable = true)
	private String system;
	// ---- 下载内容 end -----
	
	
	// ---- 视频内容    -----
	/**
	 * 视频集
	 */
	@Column(name = "s_videos", length = 4000, nullable = true)
	private String videos;
	// ---- 视频内容 end -----
	
	
	// ---- 产品内容    -----
	/**
	 * 产品图片集
	 */
	@Column(name = "s_products", length = 500, nullable = true)
	private String products;
	/**
	 * 市场价
	 */
	@Column(name = "d_market", nullable = true)
	private Double market;
	/**
	 * 优惠价
	 */
	@Column(name = "d_discount", nullable = true)
	private Double discount;
	/**
	 * 商品是否有货
	 */
	@Column(name = "b_stock", length = 10, nullable = true)
	private Boolean stock;
	// ---- 产品内容 end -----
	
	
	// ---- 文库内容    -----
	/**
	 * 文库PDF
	 */
	@Column(name = "s_pdf", length = 50, nullable = true)
	private String pdf;
	// ---- 文库内容 end -----
	
	
	// ---- 招聘内容    -----
	/**
	 * 公司名称
	 */
	@Column(name = "s_company", length = 50, nullable = true)
	private String company;

	/**
	 * 部门名称
	 */
	@Column(name = "s_department", length = 50, nullable = true)
	private String department;

	/**
	 * 招聘人数
	 */
	@Column(name = "s_number", length = 10, nullable = true)
	private Integer number;

	/**
	 * 薪酬待遇
	 */
	@Column(name = "s_salary", length = 20, nullable = true)
	private String salary;

	/**
	 * 工作经验
	 */
	@Column(name = "s_undergo", length = 50, nullable = true)
	private String undergo;

	/**
	 * 最低学历
	 */
	@Column(name = "s_education", length = 20, nullable = true)
	private String education;

	/**
	 * 工作地点
	 */
	@Column(name = "s_workingPlace", length = 50, nullable = true)
	private String workingPlace;

	/**
	 * 工作性质
	 */
	@Column(name = "s_workNature", length = 10, nullable = true)
	private String workNature;

	/**
	 * 岗位职责
	 */
	@Column(name = "s_duty", length = 1000, nullable = true)
	private String duty;

	/**
	 * 岗位要求
	 */
	@Column(name = "s_claim", length = 1000, nullable = true)
	private String claim;
	// ---- 招聘内容 end -----

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSiteId() {
		return siteId;
	}

	public void setSiteId(String siteId) {
		this.siteId = siteId;
	}

	public String getOriginalid() {
		return originalid;
	}

	public void setOriginalid(String originalid) {
		this.originalid = originalid;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getColumn() {
		return column;
	}

	public void setColumn(String column) {
		this.column = column;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getFullTitle() {
		return fullTitle;
	}

	public void setFullTitle(String fullTitle) {
		this.fullTitle = fullTitle;
	}

	public String getTitlePicture() {
		return titlePicture;
	}

	public void setTitlePicture(String titlePicture) {
		this.titlePicture = titlePicture;
	}

	public String getMain() {
		return main;
	}

	public void setMain(String main) {
		this.main = main;
	}

	public String getRelease() {
		return release;
	}

	public void setRelease(String release) {
		this.release = release;
	}

	public Date getPublishDate() {
		return publishDate;
	}

	public void setPublishDate(Date publishDate) {
		this.publishDate = publishDate;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getDescribe() {
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getImages() {
		return images;
	}

	public void setImages(String images) {
		this.images = images;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}

	public Long getSize() {
		return size;
	}

	public void setSize(Long size) {
		this.size = size;
	}

	public String getLicense() {
		return license;
	}

	public void setLicense(String license) {
		this.license = license;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public Integer getStar() {
		return star;
	}

	public void setStar(Integer star) {
		this.star = star;
	}

	public String getSystem() {
		return system;
	}

	public void setSystem(String system) {
		this.system = system;
	}

	public String getVideos() {
		return videos;
	}

	public void setVideos(String videos) {
		this.videos = videos;
	}

	public String getProducts() {
		return products;
	}

	public void setProducts(String products) {
		this.products = products;
	}

	public Double getMarket() {
		return market;
	}

	public void setMarket(Double market) {
		this.market = market;
	}

	public Double getDiscount() {
		return discount;
	}

	public void setDiscount(Double discount) {
		this.discount = discount;
	}

	public Boolean getStock() {
		return stock;
	}

	public void setStock(Boolean stock) {
		this.stock = stock;
	}

	public String getPdf() {
		return pdf;
	}

	public void setPdf(String pdf) {
		this.pdf = pdf;
	}

	public String getCompany() {
		return company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}

	public Integer getNumber() {
		return number;
	}

	public void setNumber(Integer number) {
		this.number = number;
	}

	public String getSalary() {
		return salary;
	}

	public void setSalary(String salary) {
		this.salary = salary;
	}

	public String getUndergo() {
		return undergo;
	}

	public void setUndergo(String undergo) {
		this.undergo = undergo;
	}

	public String getEducation() {
		return education;
	}

	public void setEducation(String education) {
		this.education = education;
	}

	public String getWorkingPlace() {
		return workingPlace;
	}

	public void setWorkingPlace(String workingPlace) {
		this.workingPlace = workingPlace;
	}

	public String getWorkNature() {
		return workNature;
	}

	public void setWorkNature(String workNature) {
		this.workNature = workNature;
	}

	public String getDuty() {
		return duty;
	}

	public void setDuty(String duty) {
		this.duty = duty;
	}

	public String getClaim() {
		return claim;
	}

	public void setClaim(String claim) {
		this.claim = claim;
	}

	/**
	 * 子表对象 评论管理
	 */
	@SuppressWarnings("deprecation")
	@org.hibernate.annotations.ForeignKey(name = "none")
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "s_docid")
	@OrderBy("ID ASC")
	private Set<JdbcCommentEntity> comment = new HashSet<JdbcCommentEntity>();
	
	public Set<JdbcCommentEntity> getComment() {
		return comment;
	}

	public void setComment(Set<JdbcCommentEntity> comment) {
		this.comment = comment;
	}
	
	@Override
	public void from(DocumentEntity t) {
		BeanUtils.copyProperties(t, this,new String[] {"comment"});
		//子表对象 评论管理 - start - 
		Set<JdbcCommentEntity> comment = new HashSet<JdbcCommentEntity>();
		Set<CommentEntity> entitycomment = t.getComment();
		if(entitycomment !=null) {
			for (CommentEntity item : entitycomment) {
				JdbcCommentEntity jItem = new JdbcCommentEntity();
				jItem.from(item);
				comment.add(jItem);
			}
		}
		this.setComment(comment);
		//子表对象 评论管理 - end --
		
	}

	@Override
	public DocumentEntity toEntity() {
		DocumentEntity toEntity = new DocumentEntity();
		BeanUtils.copyProperties(this, toEntity,new String[] {"comment"});
		//子表对象 评论管理 - start-
		Set<CommentEntity>  comment = new HashSet<CommentEntity>();
		Set<JdbcCommentEntity> entitycomment = this.getComment();
		if(entitycomment !=null) {
			for (JdbcCommentEntity item : entitycomment) {
				comment.add(item.toEntity());
			}
		}
		toEntity.setComment(comment);
		//子表对象 评论管理 - end - 
	
		return toEntity;
	}
	
	
}
